﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Ue.Core;
using Ue.Extensions;

namespace Ue.Components.VerificationCode
{
    public static class VerifyCodeHolder
    {
        public readonly static Color[] Colours = new Color[] {
            Color.FromArgb(215, 65, 0),
            Color.FromArgb(80, 130, 30),
            Color.FromArgb(25, 95, 135),
            Color.FromArgb(255, 153, 0), };

        public readonly static VerifyBackgroundImage[] BackgroundImages = new VerifyBackgroundImage[]{
            new VerifyBackgroundImage("Blue",new Color[] { Color.White, Color.FromArgb(255, 255, 0), Color.FromArgb(255, 102, 0) }),
            new VerifyBackgroundImage("Green", new Color[] { Color.White, Color.FromArgb(255, 255, 0), Color.FromArgb(255, 102, 0) }),
            new VerifyBackgroundImage("Brown", new Color[] { Color.White, Color.FromArgb(255, 255, 0), Color.FromArgb(153, 204, 0) })
        };

        public readonly static string[] FontFamilies = new string[]{
            "华文细黑", 
            "华文新魏", 
            "方正舒体", 
            "Arial", 
            "Basemic Symbol", 
            "Corbel", 
            "Georgia", 
            "Latha", 
            "Narkisim"
        };

        public readonly static char[] Number = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

        /// <summary>
        /// 没有大小写O、小写L、大写I
        /// </summary>
        public readonly static char[] Letters = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

        public readonly static int Noise = 20;

        public readonly static int Distortion = 20;

        #region 取得随机数

        internal static int GetRandom(int maxNumber)
        {
            return  VerifyCodeHolder.GetRandom(0, maxNumber);
        }
        internal static int GetRandom(int minNumber, int maxNumber)
        {
            return Globals.Random.Next(minNumber, maxNumber);
        }

        #endregion

        public static IEnumerable<FontFamily> GetFontFamilies(string[] fontNames)
        {
            IList<FontFamily> results = new List<FontFamily>();
            foreach (string fontName in fontNames)
            {
                try
                {
                    results.Add(new FontFamily(fontName));
                }
                catch
                {

                }
            }

            return results;
        }
    }
}
